package net.alan.modules.repository;

import net.alan.modules.bean.DataStat;
import net.alan.modules.bean.Task;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Author 李岩飞
 * Email eliyanfei@126.com
 * 2017/11/22
 */
public interface TaskRepository extends JpaRepository<Task, Integer> {
    /**
     * 根据组Id查询任务
     *
     * @param pageable
     * @return
     */
    @Query("select t from Task t where t.projectId = ?1 and (t.fromUserId = ?2 or t.toUserId=?2)")
    public Page<Task> findByProjectIdAndToUserIdOrFromUserId(Integer projectId, Integer userId, Pageable pageable);


    @Query(value = "select count(id) as l1,sum(done) as l2 from task  where project_id = ?1", nativeQuery = true)
    public List<Object[]> statTask(Integer projectId);

    @Query(value = "select to_user_id as l1,count(id) as l2,sum(done) as l3 from task  where project_id = ?1 group by to_user_id", nativeQuery = true)
    public List<Object[]> statList(Integer projectId);

}
